﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Newtonsoft.Json;
using Emz.Core.Models;

namespace Legazpi.Payroll.Web.Models
{
    public class EmployeeDTR
    {
        public int Id { get; set; }
        public int EmployeeId { get; set; }
        public int PayDateId { get; set; }
        public string EmployeeName { get; set; }
        public double WorkHours { get; set; }
        public double OverTime { get; set; }
        public double NightDiff { get; set; }
        public int Holiday { get; set; }

        private List<TimeRecord> timeRecords;
        public  List<TimeRecord> TimeRecords 
        {
            get 
            {
                return timeRecords ?? new List<TimeRecord>();
            }
            set
            {
                timeRecords = value;
            }
        }

        #region Static Methods
        
            public static EmployeeDTR GetDTO(DayTimeRecord dtr)
            {
                return new EmployeeDTR
                {
                    Id = dtr.Id,
                    EmployeeId = dtr.EmployeeId,
                    PayDateId = dtr.PayrollDateId,
                    EmployeeName = string.Format("{0}, {1} {2}", dtr.Employee.LastName,dtr.Employee.FirstName,dtr.Employee.MiddleName),
                    TimeRecords = dtr.TimeRecords,
                    WorkHours = dtr.RegularTimeHours + dtr.LegalHolidayTimeHours + dtr.SpecialHolidayTimeHours,
                    OverTime = dtr.TotalOverTime,
                    NightDiff  = dtr.TotalNightDifferential         
                };
            }
        #endregion

    }
}